#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
int main()
{
    int n, a[10];
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);
    }
    int min = a[0], min_num = 0, max = a[n - 1], max_num = n - 1;
    int temp1,temp2, i;
    for (i = 0; i < n ; i++)
    {
        if (a[i] <=min)
        {
            min = a[i];
            min_num = i;
        }
        if (a[i] >= max)
        {
            max = a[i];
            max_num = i;
        }
    }
    temp1 = a[min_num];
    a[min_num] = a[0];
    a[0] = temp1;
    if (max_num == 0)
    {
        max_num = min_num;
    }
    temp2 = a[max_num];
    a[max_num] = a[n-1];
    a[n-1] = temp2;
    for (int j = 0; j < n; j++)
    {
        printf("%d ", a[j]);
    }
    return 0;
}